package com.huawei.leetcode;

import java.util.HashMap;
import java.util.Map;

public class Code128 {

    public static void main(String[] args) {
        int[] nums={100,4,200,1,3,2};
        new Code128().longestConsecutive(nums);
    }
    public int longestConsecutive(int[] nums) {
        if(nums.length==0 || nums == null){
            return 0;
        }
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            map.put(nums[i], i);
        }
        int max = 1;
        int count =1;
//        for (int i = (int) Math.pow(10.0, 9.0) * -1; i <= (int) Math.pow(10.0, 9.0)-1; i++) {
        for (int i = -10000; i <= 10000; i++) {
            if(map.containsKey(i)&& map.containsKey(i+1)){
                count++;
            }else {
                max = Math.max(max,count);
                count = 0;
            }
        }
        return max;
    }
}
